package org.example.entity;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;  // 明确使用 java.sql.Date

/**
 * DTO 类，专门用来保存查询到的结果
 */
public class EmployeeDTO {
    private Integer empId;  // 添加 empId 字段
    private String empName;
    private String job;
    private Date hireDate;
    private double sal;
    private double comm;
    private String deptName;
    private String deptLoc;

    // 更新构造函数
    public EmployeeDTO(Integer empId, String empName, String job, Date hireDate, double sal, double comm, String deptName, String deptLoc) {
        this.empId = empId;
        this.empName = empName;
        this.job = job;
        this.hireDate = hireDate;
        this.sal = sal;
        this.comm = comm;
        this.deptName = deptName;
        this.deptLoc = deptLoc;
    }

    // 添加 empId 的 getter 和 setter
    public Integer getEmpId() {
        return empId;
    }

    public void setEmpId(Integer empId) {
        this.empId = empId;
    }

    // 其他 getter 和 setter 保持不变...
    public String getEmpName() { return empName; }
    public void setEmpName(String empName) { this.empName = empName; }
    public String getJob() { return job; }
    public void setJob(String job) { this.job = job; }
    public Date getHireDate() { return hireDate; }
    public void setHireDate(Date hireDate) { this.hireDate = hireDate; }
    public double getSal() { return sal; }
    public void setSal(double sal) { this.sal = sal; }
    public double getComm() { return comm; }
    public void setComm(double comm) { this.comm = comm; }
    public String getDeptName() { return deptName; }
    public void setDeptName(String deptName) { this.deptName = deptName; }
    public String getDeptLoc() { return deptLoc; }
    public void setDeptLoc(String deptLoc) { this.deptLoc = deptLoc; }

    @Override
    public String toString() {
        return "EmployeeDTO{" +
                "empId=" + empId +  // 添加 empId 到 toString
                ", empName='" + empName + '\'' +
                ", job='" + job + '\'' +
                ", hireDate=" + hireDate +
                ", sal=" + sal +
                ", comm=" + comm +
                ", deptName='" + deptName + '\'' +
                ", deptLoc='" + deptLoc + '\'' +
                '}';
    }

    // 更新静态映射方法
    public static EmployeeDTO map(ResultSet rs) throws SQLException {
        return new EmployeeDTO(
                rs.getInt("emp_id"),  // 添加 emp_id 映射
                rs.getString("emp_name"),
                rs.getString("job"),
                rs.getDate("hire_date"),
                rs.getDouble("sal"),
                rs.getDouble("comm"),
                rs.getString("dept_name"),
                rs.getString("dept_loc")
        );
    }
}